<?php
namespace Siter\Controller;

class ZonePlanStatsController extends Controller {

    public function index() {
        try {
            $m     = D('ZonePlanStats');
            $day = I('get.day', date('Y-m-d'), 'trim');
            $this->indexExpr = ['day' => $day];
            $field = 'day, plan_type, SUM(num) AS num, SUM(siter_income) AS siter_income';
            $this->sortExpr = 'num DESC';
            $record = $m->field($field)->where($this->indexExpr)->group('day, plan_type')->order('day DESC')->select();
            $total  = array('num' => 0, 'siter_income' => 0);

            if(!empty($record)) {
                foreach($record as $v) {
                    $total['num']          += $v['num'];
                    $total['siter_income']  = bcadd($total['siter_income'], $v['siter_income'], C('MONEY_SCALE'));
                }
            }

            $this->assign('total', $total);
            $this->assign('record', $record);
        } catch(\Exception $e) {
        }

        $this->display();
    }

}
